/**
 * Created with IntelliJ IDEA.
 *
 * @author: cxs
 * @date: 2023/6/26
 * @time: 20:15
 * @className：WebUtils
 * @description：
 */
package com.bailan.common.util;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class WebUtils {
    public  static ServletRequestAttributes getServletRequestAttributes(){
        return (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    }

    /**
     * 获取当前线程的请求对象
     * @return
     */
    public  static HttpServletRequest getHttpServletRequest(){
        return  getServletRequestAttributes().getRequest();
    }

    /**
     * 获取当前线程的响应对象
     * @return
     */
    public  static HttpServletResponse getHttpServletResponse(){
        return  getServletRequestAttributes().getResponse();
    }

    /**
     * 获取session对象
     * @return
     */
    public static HttpSession getHttpSession(){
        return  getHttpServletRequest().getSession();
    }

    /**
     * 获取servletContext对象
     * @return
     */
    public  static String getServletContext(){
        return  getHttpServletRequest().getServletPath();
    }

}
